import base64

import requests

from codes.commons.configs import easiest_common_headers as common_headers

key_ = 'yuanrenxue'


def get_m(page: int):
    return base64.b64encode((key_ + str(page)).encode())


def request_pages():
    url = 'http://match.yuanrenxue.com/api/match/12'
    num_total = 0
    for p in range(1, 6):
        params = {
            'page': p,
            'm': get_m(p)
        }
        res_json = requests.get(url=url, params=params, headers=common_headers).json()
        print(f'获取第【{p}】页数据：{res_json}')
        for d in res_json['data']:
            num_total += d['value']
    print('总计: ', num_total)


if __name__ == '__main__':
    request_pages()
